package com.mhz.echartsdemo.controller;


import com.mhz.echartsdemo.pojo.subject.SubjectOne;
import com.mhz.echartsdemo.service.EduSubjectService;
import com.mhz.echartsdemo.service.MovieService;
import com.mhz.echartsdemo.service.StatisticsDailyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author mhz
 * @since 2021-03-30
 */
@Controller
@RequestMapping()
public class StatisticsDailyController {

    @Autowired
    StatisticsDailyService dailyService;

    @Autowired
    EduSubjectService subjectService;

    @Autowired
    MovieService movieService;

    @GetMapping("bar")
    public String showBarChart(Model model) {
        Map<String, Object> map = subjectService.getChartData();
        model.addAttribute("dataBar", map);
        return "echarts/bar";
    }

    @GetMapping("line")
    public String showLineChart(Model model) {
        Map<String, Object> map = dailyService.getChartData();
//        List<String> xDate = (List<String>) map.get("calculatedList");
//        List<Integer> yDate = (List<Integer>) map.get("numDateList");
//        model.addAttribute("xDate",xDate);
//        model.addAttribute("yDate",yDate);
//        System.out.println("map==========" + xDate + yDate);
        System.out.println(map);
        model.addAttribute("dataLine", map);
        return "echarts/line";
    }

    @GetMapping("pie")
    public String showPieChart(Model model) {
        List<Map<String,String>> list = movieService.getChartData();
        model.addAttribute("dataPie", list);
        return "echarts/pie";
    }

    @GetMapping("funnel")
    public String showFunnelChart(Model model) {
        List<Map<String,String>> list = movieService.getChartData();
        model.addAttribute("dataFunnel", list);
        return "echarts/funnel";
    }
    @GetMapping("tree")
    public String showTreeChart(Model model) {
        SubjectOne list = subjectService.getTreeData();
        model.addAttribute("dataTree", list);
        return "echarts/tree";
    }


    @GetMapping("getLineLogin")
    @ResponseBody
    public Map<String, Object> showLineChartLogin() {
        Map<String, Object> map = dailyService.getChartData();
        return map;
    }

    @GetMapping("getLineVideo")
    @ResponseBody
    public Map<String, Object> showLineChartVideo() {
        Map<String, Object> map = dailyService.getChartDataVideo();
        return map;
    }
    @GetMapping("getLineCourse")
    @ResponseBody
    public Map<String, Object> showLineChartCourse() {
        Map<String, Object> map = dailyService.getChartDataCouse();
        return map;
    }
    @GetMapping("getLineRegister")
    @ResponseBody
    public Map<String, Object> showLineChartRegister() {
        Map<String, Object> map = dailyService.getChartDataRegister();
        return map;
    }
}

